/*
 * ZooServlet.java
 *
 * Created on March 20, 2004, 10:43 AM
 */

import javax.servlet.http.HttpServlet;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;

import bd.Nucleaire;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


public class letsax {
    
    TransformerHandler th;
    Attributes atts;
    
    public void go() throws TransformerConfigurationException, SAXException{
        initXml();
    }
    
    public void initXml() throws TransformerConfigurationException, SAXException{
        SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
        th = tf.newTransformerHandler();
         javax.xml.transform.Transformer serializer = th.getTransformer();
         serializer.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1");
        // pretty XML output
        serializer.setOutputProperty
            ("{http://xml.apache.org/xslt}indent-amount", "4");
        serializer.setOutputProperty(OutputKeys.INDENT,"yes");
        // output
         th.setResult(null);
    
        th.startDocument();
        atts = new AttributesImpl();
        th.startElement("","Base_nucleaire","Base_nucleaire",atts);
    }
    public void close() throws SAXException{
        th.endElement("","Base_nucleaire","Base_nucleaire");
        th.endDocument();  
    }
    public void useData(Nucleaire[] nucleaires){
         
        try {
        	
        	for(Nucleaire nuc : nucleaires){
				th.startElement("","","NomMissille",atts);
				th.characters(nuc.getNomNucleaire().toCharArray(), 0, nuc.getNomNucleaire().length());
				th.endElement("","","NomMissille");
        	}
		} catch (SAXException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        
    }
    
}
